package com.lgy.core.task;
import com.lgy.core.base.AbstractTask;
import com.lgy.service.ServInfoService;
import com.lgy.utils.FrameTimeUtil;
import org.apache.log4j.Logger;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 清空任务日志的定时任务类
 * @author yuejing
 * @date 2015年3月29日 下午10:05:34
 * @version V1.0.0
 */
@Component
public class CleanTask extends AbstractTask {
	private static final Logger LOGGER = Logger.getLogger(CleanTask.class);

	@Autowired
	private ServInfoService servInfoService;

	@Override
	public void execute(JobExecutionContext context) {
		System.out.println("=========================== CleanTask ====================");
		String siValue = "7";
		Date siDate = FrameTimeUtil.addDays(FrameTimeUtil.getTime(), - Integer.valueOf(siValue));
		//清空小于指定日期的已停止的服务
		servInfoService.deleteDestroyLtDate(siDate);
		
		//修改已销毁的服务为非Leader
		servInfoService.destroyLeader();

	}
}